import os
import numpy
import cv2

drawing = False
drawType = True
img = numpy.zeros([512, 512, 3], numpy.uint8)
initX = -1
initY = -1
def darw_cricle(event, x, y, flag, param):
    global drawing, drawType, initX, initY
    if event == cv2.EVENT_LBUTTONDOWN:
        drawing = True
        initX = x
        initY = y
    if event == cv2.EVENT_MOUSEMOVE:
        if drawing == True:
            if drawType == True:
                cv2.circle(img, (x, y), 5, (255, 255, 0), -1)
            else:
                cv2.rectangle(img, (initX, initY), (x, y), (255, 0 , 255), -1)
        
    if event == cv2.EVENT_LBUTTONUP:
        if drawing == True:
            if drawType == False:
                cv2.rectangle(img, (initX, initY), (x, y), (255, 0, 234), -1)
            else:
                cv2.circle(img, (x, y), 5, (255, 255, 0), -1)
                pass
        drawing = False
cv2.namedWindow("img")
cv2.setMouseCallback("img", darw_cricle)
cv2.waitKey(1)
while True:
    cv2.imshow("img", img)
    key = cv2.waitKey(1) & 0xff
    if key == ord("m"):
        print("=================================")
        print(drawType)
        drawType = not drawType
    elif key == ord("q"):
        break
cv2.destroyAllWindows()
        

